<?php
/**
 * Created by PhpStorm.
 * User: YUWENXUAN
 * Date: 2017/4/14
 * Time: 18:29
 */
interface Logger{
    public function log(string $msg);
}
class Application{
    private $logger;

    /**
     * @return mixed
     */
    public function getLogger():Logger
    {
        return $this->logger;
    }

    /**
     * @param mixed $logger
     */
    public function setLogger(Logger $logger)
    {
        $this->logger = $logger;
    }

}
$app =new Application();
// 使用new class 创建匿名类

$app->setLogger(new class implements Logger{
    public function log(string $msg)
    {
        // TODO: Implement log() method.
        print ($msg)."匿名类"."<br>";
    }
});
$app->getLogger()->log("我的第一条日志");